var getCookie = readCookie("user")
$("#myId").val(getCookie)
getUserInfo()
getVue()
getAddress()
var myFlag=""
function getUserInfo(){
	$.ajax({
		url:"http://localhost:8080/user/login",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie
			},
		async:false,
		success:function(data){
			
			$("#img1").prop("src","http://localhost:8080/"+data.data.img)
		}
	})
}
function getVue(){
	vm=new Vue({
		el:".right_style",
		data:{
			sinfo:[]
		},methods:{
			updateAddress(id){
				$(".submit—btn").val("修改")
				findUserById(id)
			},
			deleteAddress(id){
				myFlag=id
				 $.DialogByZ.Confirm({Title: "", Content: "是否确定删除",FunL:confirmL,FunR:Immediate})
			},
			addAddress(){
				$("#uId").val(getCookie)
				var town=$("#town").val()
				if($(".submit—btn").val()=="修改"&&town!="请选择"){
					updateAddress()
				}else if($(".submit—btn").val()=="添加"){
					
					addAddress()
				}else if(town=="请选择"){
					$.DialogByZ.Alert({Title: "提示", Content: "地址不能为空",BtnL:"确定"})
					
				}
				
			}
		}
		
	})
}
  function confirmL(){
		//alert("kk")
		$.DialogByZ.Close();
		deleteAddress(myFlag)
   }
   function Immediate(){
   	$.DialogByZ.Close();
      }
function findUserById(id){
	$.ajax({
		url:"http://localhost:8080/address/selectById",
		data:{"id":id},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			$("input[name='id']").val(id)
			$("#uId").val(data.data.uId)
			$("input[name='receiver']").val(data.data.receiver)
			$("input[name='street']").val(data.data.street)
			$("input[name='email']").val(data.data.email)
			$("input[name='tel']").val(data.data.tel)
		}
	})
	
	}
function addAddress(){
	$.ajax({
		url:"http://localhost:8080/address/add",
		data:$("#form1").serialize(),
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			if(data.status==1){
				
				 $.DialogByZ.Autofade({Content: "添加成功"})
				getAddress()
				$(".submit—btn").val("添加")
			}else{
				$.DialogByZ.Alert({Title: "提示", Content:data.msg,BtnL:"确定"})
			}
			
			
		
		}
	})
}
function updateAddress(){
	$.ajax({
		url:"http://localhost:8080/address/update",
		data:$("#form1").serialize(),
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			if(data.status==1){
				$.DialogByZ.Autofade({Content: "修改成功"})
				getAddress()
				$(".submit—btn").val("添加")
				
				
				
				$("input[name='id']").val("")
				
				$("input[name='receiver']").val("")
				$("input[name='street']").val("")
				$("input[name='email']").val("")
				$("input[name='tel']").val("")
			}else{
				$.DialogByZ.Alert({Title: "提示", Content:data.msg,BtnL:"确定"})
			}
			
			
		
		}
	})
}
function deleteAddress(id){
	$.ajax({
		url:"http://localhost:8080/address/delete",
		data:{"id":id},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			
			if(data.status==1){
				getAddress()
			}else{
				$.DialogByZ.Autofade({Content:data.msg})
				
			}
			
		
		}
	})
}
function getAddress(){
	$.ajax({
		url:"http://localhost:8080/address/selectByUid",
		data:{"uId":getCookie},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			
			vm.$data.sinfo=data.data
			
		
		}
	})
}
